﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using ECCSystem.BizRule;
namespace ECCSystem
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void btnReports_Click(object sender, EventArgs e)
        {
            Form frmReports = new frmReportsMain();
            frmReports.Show();
            this.Hide();
        }

        private void btnEntryData_Click(object sender, EventArgs e)
        {
			frmEntrySearch objfrmEntrySearch = new frmEntrySearch(0);
			objfrmEntrySearch.Show();
			this.Hide();

			//Tiger 2008/07/10 del start
			//Form frmEntryMains = new frmEntryMain();
			//frmEntryMains.Show();
			//this.Hide();
			//Tiger 2008/07/10 del end
        }

        private void btnJapans_Click(object sender, EventArgs e)
        {
            Form frmJapan = new frmJapans();
            frmJapan.Show();
            this.Hide();
        }

        private void btnExtras_Click(object sender, EventArgs e)
        {
            Form frmExtra = new frmExtras();
            frmExtra.Show();
            this.Hide();
        }

        private void btnSaleCommodity_Click(object sender, EventArgs e)
        {
            Form frmSale = new frmSaleCommodity();
            frmSale.Show();
            this.Hide();
        }

        private void btnMailCategory_Click(object sender, EventArgs e)
        {
            Form frmMail = new frmMailCategory();
            frmMail.Show();
            this.Hide();
        }

        private void btnUserMgst_Click(object sender, EventArgs e)
        {
            Form frmUser = new frmUserMaintenance();
            frmUser.Show();
            this.Hide();
        }

        private void btnDeleteHistoryData_Click(object sender, EventArgs e)
        {
            Form frmHistory = new frmDeleteHistoryData();
            frmHistory.Show();
            this.Hide();
        }

        private void btnLogOut_Click(object sender, EventArgs e)
        {
			try
			{
				////write system log
				BizRule.ClsSystemLog objBRLog = new ECCSystem.BizRule.ClsSystemLog();
				objBRLog.AddSystemLog("Log off");
				string strIP = " ";
				ClsUserMaintenance objClsUserMaintenance = new ClsUserMaintenance();
				objClsUserMaintenance.EditUser(strIP);
				//this._bwMessenger.CancelAsync();
				//this._bwMessenger.Dispose();
				//close database connection
				System.GC.Collect();
				if (BizRule.ClsCommon.gObjConn != null)
				{
					BizRule.ClsCommon.gObjConn.Close();
				}
				if (BizRule.ClsCommon.gfrmMessage != null)
				{
					BizRule.ClsCommon.gfrmMessage.objBackgroundWorker.CancelAsync();
					BizRule.ClsCommon.gfrmMessage.objBackgroundWorker = null;
					BizRule.ClsCommon.gfrmMessage.Close();
					BizRule.ClsCommon.gfrmMessage = null;
				}

				System.Windows.Forms.Application.Exit();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.ToString(), "ECC Catch Error");
				System.Windows.Forms.Application.Exit();
			}
			finally
			{
				System.Windows.Forms.Application.Exit();
			}
        }

        //Load event
        private void frmMain_Load(object sender, EventArgs e)
        {
            if (BizRule.ClsCommon.gStrRight.ToString() != "")
            {
                if (BizRule.ClsCommon.gStrRight == "CSR")
                {
                    btnDeleteHistoryData.Enabled = false;
                    btnExtras.Enabled = false;
                    btnJapans.Enabled = false;
                    btnMailCategory.Enabled = false;
					//btnReports.Enabled = false;
                    btnSaleCommodity.Enabled = false;
                    btnUserMgst.Enabled = false;
					//btnTemplate.Enabled = false;
					btnCategory.Enabled = false;
					btnOverTimeBill.Enabled = false;
					btnMailKeyName.Enabled = false;
					btnEmailAppoint.Enabled = false;
					btnDefect.Enabled = false;
					//btnRule.Enabled = false;
					btnWorkTime.Enabled = false;
					btnTeamGoal.Enabled = false;
                }
                if (BizRule.ClsCommon.gStrRight == "SV")
                {
                    btnDeleteHistoryData.Enabled = false;
					btnMailCategory.Enabled = false;
					btnMailKeyName.Enabled = false;
					//btnTemplate.Enabled = false;
                    btnUserMgst.Enabled = false;
					//btnRule.Enabled = false;
					btnTeamGoal.Enabled = false;
                }

            }


        }

		private void btnTemplate_Click(object sender, EventArgs e)
		{
			Form frmTemplate = new frmTemplateImportAndInput(0);
			frmTemplate.Show();
			this.Hide();
		}

		private void btnMailKeyName_Click(object sender, EventArgs e)
		{
			Form frmTemplate = new frmMailKeyName();
			frmTemplate.Show();
			this.Hide();
		}

		private void btnCategory_Click(object sender, EventArgs e)
		{
			Form frmTemplate = new frmMailCategory();
			frmTemplate.Show();
			this.Hide();
		}

		private void btnOverTimeBill_Click(object sender, EventArgs e)
		{
			Form frmTemplate = new frmOverBill();
			frmTemplate.Show();
			this.Hide();
		}

		private void btnEmailAppoint_Click(object sender, EventArgs e)
		{
			Form frmTemplate = new frmEmailAppoint();
			frmTemplate.Show();
			this.Hide();
		}

		private void btnDefect_Click(object sender, EventArgs e)
		{
			Form frmTemplate = new frmDefect();
			frmTemplate.Show();
			this.Hide();
		}

		private void btnRule_Click(object sender, EventArgs e)
		{
			Form frmTemplate = new frmRule();
			frmTemplate.Show();
			this.Hide();
		}

        private void btnExtSetting_Click(object sender, EventArgs e)
        {
            frm_Ext_Setting _frmExtSetting = new frm_Ext_Setting();
            
            this.Hide();
            _frmExtSetting.ShowDialog();
            this.Show();
        }

		private void btnMailCheck_Click(object sender, EventArgs e)
		{
			Form objfrmWorkTime = new frmWorkTime();
			objfrmWorkTime.Show();
			this.Hide();
		}

		private void btnTeamGoal_Click(object sender, EventArgs e)
		{
			Form objfrmTeamGoal = new frmTeamGoal();
			objfrmTeamGoal.Show();
			this.Hide();
			
		}

        private void btnExtFollowingWork_Click(object sender, EventArgs e)
        {
            frm_Ext_FollowingWork _frmExtFollowingWork = new frm_Ext_FollowingWork();
            this.Hide();
            _frmExtFollowingWork.ShowDialog();
            this.Show();
        }

	
    }
}